﻿namespace TomatoClock.Services
{
    public class BackgroundManager
    {
        private readonly string BackgroundFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "resource", "background");
        private List<string> BackgroundPaths = new List<string>();
        public BackgroundManager()
        {
            Directory.CreateDirectory(BackgroundFolder); // Ensure the directory exists
            LoadBackgroundPaths();
        }

        public void AddBackgroundPaths(string path)
        {
            BackgroundPaths.Add(path);
            SaveBackgroundPaths();
        }

        public void RemoveBackgroundPaths(string path)
        {
            BackgroundPaths.Remove(path);
            SaveBackgroundPaths();
        }

        public List<string> GetBackgroundPaths()
        {
            return BackgroundPaths;
        }
        private void LoadBackgroundPaths()
        {
            string filePath = Path.Combine(BackgroundFolder, "picturePaths.txt");
            if (File.Exists(filePath))
            {
                string[] paths = File.ReadAllLines(filePath);
                BackgroundPaths = paths.ToList();
            }
        }

        public void SaveBackgroundPaths()
        {
            string filePath = Path.Combine(BackgroundFolder, "picturePaths.txt");
            File.WriteAllLines(filePath, BackgroundPaths);
        }
    }
}
